package com.wits.qso.dao.impl;

import java.util.List;

import javax.persistence.Query;

import org.springframework.stereotype.Component;

import com.wits.platform.dao.impl.BaseDaoImpl;
import com.wits.qso.dao.custom.DiscussionMemberDaoCustom;
import com.wits.qso.entity.DiscussionMember;
import com.wits.qso.entity.DiscussionMemberPK;

@Component
public class DiscussionMemberDaoImpl extends BaseDaoImpl<DiscussionMember,DiscussionMemberPK> implements DiscussionMemberDaoCustom{

	
	@SuppressWarnings("unchecked")
	@Override
	public List<String> findMemberIdByGroupId(String groupId) {
		String sql="select dm.user_id from qso_discussion_member dm where dm.group_id=?";
		return this.em.createNativeQuery(sql).setParameter(1, groupId).getResultList();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<DiscussionMember> findMemberByGroupId(String groupId) {
		String sql="select dm.group_id,dm.user_id,u.user_name_c as user_name,dm.status from wits_user u left join qso_discussion_member dm on(u.user_id=dm.user_id) where dm.group_id=:groupId";
        Query query=em.createNativeQuery(sql, DiscussionMember.class);
        query.setParameter("groupId", groupId);
		return query.getResultList();
	}


	@Override
	public List<DiscussionMember> findByGroupIdAndNotEqStatus(String groupId,
			int status) {
		String sql="select dm.group_id,dm.user_id,u.user_name_c as user_name,dm.status from wits_user u left join qso_discussion_member dm on(u.user_id=dm.user_id) where dm.group_id=?1 and dm.status!=?2";
		return this.findByNative(DiscussionMember.class, sql, groupId,status);
		/*Query query=em.createNativeQuery(sql, DiscussionMember.class);
        query.setParameter("groupId", groupId);
		return query.getResultList();*/
	}

	@Override
	public List<String> findMemberIdByGroupIdAndNotEqStatus(String groupId,
			int status) {
		String sql="select dm.user_id from qso_discussion_member dm where dm.group_id=? and dm.status!=?";
		Query query=em.createNativeQuery(sql);
		query.setParameter(1, groupId);
		query.setParameter(2, status);
		return query.getResultList();
	}
}
